/*
 * @Author: 
 * @Date: 2021-12-18 19:54:33
 * @LastEditTime: 2021-12-18 21:51:34
 * @FilePath: /vue3-vite2-ts-antdv/vite.config.ts
 */
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ViteComponents from "unplugin-vue-components/vite";
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // vite 支持 vue 单页面
    vue(),
    // 支持 tsx
    vueJsx(),
    // ant-design-vue 按需导入
    ViteComponents({
      resolvers: [
        AntDesignVueResolver({
          importStyle: "less",
        }),
      ],
      dts: true,
      // customLoaderMatcher
      include: [/\\.vue$/, /\\.vue\\?vue/, /\\.md$/],
    }),
  ],
  css: {
    preprocessorOptions: {
      less: {
        // 自定义主题变量
        // "@primary-color": "#0083FF",
        // 支持less
        javascriptEnabled: true,
      },
    },
  },
  // 配置别名
  resolve: {
    alias: [
      { find: /^@\//, replacement: `${path.resolve(__dirname, "./src")}/` },
    ],
  },
    //启动服务配置
  server: {
    host: '0.0.0.0',
    port: 5000, // 设置服务启动端口号
    open: true, // 设置服务启动时是否自动打开浏览器
    https: false,
    cors: true, // 允许跨域
    // 代理
    proxy: {
      '/api': {
        target: 'http://API网关所在域名',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace('/api/', '/')
      }
    }
  }
})
